<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Recharge_model extends MY_Model
{
	function Recharge_model()
	{
		parent::MY_Model();
	}
	
	function get_user_info($userid)
	{
		return $this->getRows("CALL selfserving_get_user_info($userid)", false);
	}
	
	function get_user_group_info($gid)
	{
		return $this->getRows("CALL selfserving_group_info($gid)", false, 'object');
	}
	
	function get_recharge_info($id)
	{
		return $this->getRows("CALL selfserving_request_recharge_info($id)", false, 'object');
	}
	
	function getlist_user_by_group($gid)
	{
		return $this->getRows("CALL selfserving_getlist_users_by_group($gid)", true, 'object');
	}
	
	function insert_request_recharge($create_by, $for_uid, $type_user, $money, $content, $type_pay, $receipts, $desc = '', $typead = 1, $status = 1)
	{
		$id = $this->getRows("CALL selfserving_request_recharge_insert($create_by,$for_uid,$type_user,$money,'$content','$type_pay','$receipts','$desc',$typead,$status);", false, 'object');
		return (int)$id->id;
	}
	
	function updateStatusRecharge($id, $status, $uid, $real_money, $comment = '', $type = 1)
	{
		$this->exeQuery("CALL selfserving_request_recharge_update_status($id,$status,$uid,$real_money,'$comment',$type);");
	}
	
	function add_money($cusid, $typeuser, $money, $content = '', $typepay, $link_money, $date, $uid)
	{
		$this->exeQuery("CALL selfserving_add_money($cusid, $typeuser, $money, '$content', '$typepay', '$link_money', '$date', $uid);");
	}
	
	function add_money_cpm4k($cusid, $typeuser, $money, $content = '', $typepay, $link_money, $date, $uid)
	{
		$this->exeQuery("CALL ssv_add_money($cusid, $money, '$content', $typeuser, '$date', '$link_money', '$typepay', $uid);");
	}
	
	function recharge_getall($status, $fromdate, $todate, $keyword = '', $page = 1, $limit = 20, $typead = 1, $sch_userid)
	{
		$result = $this->getRowsOnMultiQuery("CALL selfserving_request_recharge_getall($status,'$fromdate','$todate',$page,$limit,'$keyword',$typead, $sch_userid);", 'object');
		$data = array();
		$data['items'] = $result[0];
		$data['pages'] = $result[1][0]->totalpage;
		return $data;
	}
	
	function getall_user()
	{
		return $this->getRows("CALL selfserving_users_getlist();", true, 'object');
	}
	
	function getall_agency()
	{
		return $this->getRows("CALL selfserving_get_user_group_listall();", true, 'object');
	}
	
	function checkLogin($username, $password)
	{
		return $this->getRows("CALL selfserving_login('$username', '$password');", false, 'object');
	}
	
	function email_log_insert($send, $receive, $cc, $subject, $content, $objectid, $userid, $typenotify = 3, $note = '', $typead = 0)
	{
		$this->exeQuery("CALL selfserving_email_log_insert('$send','$receive','$cc','$subject','$content',$typenotify,$objectid,$userid,'$note',$typead);");
	}
	
	function get_user_group_listall()
	{
		return $this->getRows("CALL selfserving_get_user_group_listall();", true, 'object');
	}
	
	function get_user_info_by_uname($uname)
	{
		return $this->getRows("CALL selfserving_get_user_info_by_uname('$uname');", false, 'object');
	}
}